<template>
	<div>
		
		<van-address-edit
		  :area-list="areaList"
		  
		  show-delete
		  show-set-default
		  show-search-result
		  :search-result="searchResult"
		  :area-columns-placeholder="['请选择', '请选择', '请选择']"
		  @save="onSave"
		  @delete="onDelete"
		  @change-detail="onChangeDetail"
		/>
		<router-view></router-view>
	</div>
	
</template>

<script>
	import { AddressEdit,Toast,NavBar,Notify    } from 'vant';
	import areaList  from './areaList/index.js'
	import API from '../utils/API.js'
	export default {
	  data() {
	    return {
			areaList,
	      searchResult: [],
	    };
	  },
	
	  methods: {
		     onClickLeft() {
		   this.$router.go(-1)
			 
		      },
		     
	    onSave(e) {
	     console.log(e)
		 let token = this.$store.state.token
		 this.$post(API.POST_ADDRESS_SAVE,{
			 token:token,
			 name:e.name,
			 tel:e.tel,
			 province:e.province,
			 city:e.city,
			 county:e.county,
			 addressDetail:e.addressDetail,
			 isDefault:e.isDefault
			 
		 })
		 .then(res => {
			 Notify({
			   message: '地址添加成功',
			   color: '#ffffff',
			   background: '#ffe1e1',
			 });
			 console.log(res)
		 })
	    },
	    onDelete() {
	       console.log(e)
	    },
	    onChangeDetail(val) {
			  console.log(val)
	      if (val) {
	        this.searchResult = [
	          {
	            name: '黄龙万科中心',
	            address: '杭州市西湖区',
	          },
	        ];
	      } else {
	        this.searchResult = [];
	      }
	    },
	  },
	  components:{
		  [AddressEdit.name]:AddressEdit,
		   [Toast.name]:Toast ,
		    [NavBar.name]:NavBar
	  },
	  
	  created() {
		
	  },
	
	  // beforeRouteEnter (to, from, next) {
	  //     // 注意，在路由进入之前，组件实例还未渲染，所以无法获取this实例，只能通过vm来访问组件实例
		 //    console.log(from.name)
	  //     next(vm => {})
		 //  console.log(from)
	  // }
	};
</script>

 <style lang="less" scoped>
	
</style>
